package com.nb.dp.controller;

import com.nb.dp.strategy.v1.PayContext;
import com.nb.dp.strategy.v1.PayModel;
import com.nb.dp.strategy.v2.PayFactoryByAware;
import com.nb.dp.strategy.v3.PayFactory3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author lihaoyang6
 * @date 2023年11月28日 19:58
 */
@RestController
@RequestMapping("")
public class StrategyController {

    @Autowired
    PayContext payContext;

    @Autowired
    PayFactoryByAware payFactory;

    @Autowired
    PayFactory3 payFactory3;

    @GetMapping("/v1/strategy")
    public String testStrategy(String payType,int payMoney){
        PayModel payModel = new PayModel(payType,new BigDecimal(payMoney));
        return payContext.doPay(payModel);
    }

    @GetMapping("/v2/strategy")
    public String testStrategy2(String payType,int payMoney){
        PayModel payModel = new PayModel(payType,new BigDecimal(payMoney));
        return payFactory.getPayStrategy(payType).doPay(payModel.getPayMoney());
    }


    @GetMapping("/v3/strategy")
    public String testStrategy3(String payType,int payMoney){
        PayModel payModel = new PayModel(payType,new BigDecimal(payMoney));
        return payFactory3.getPayService(payType).doPay(payModel.getPayMoney());
    }
}
